iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 7
0
Software Development

Linux從零開始系列 第 7

Linux從零開始(7/30): 登錄檔查閱

  • 分享至 

  • xImage
  •  

登錄檔啊(遠目
一種平常放著不用的時侯覺得佔空間,需要用的時侯落落長看到快要獲得血輪眼了說......

方法1.
直接用 vim 或 vi 指令看log

方法2.

直接用journalctl指令檢視
檢視需要管理權限,記得蘇一下~~~

[test@localhost ~]$ journalctl
No journal files were found.
[test@localhost ~]$ sudo su root
[sudo] password for test: 
[root@localhost test]# journalctl

什麼參數都不加原汁原味的登錄檔資料就跟 /var/log/messages 差不多

[root@localhost test]# journalctl
-- Logs begin at 一 2018-01-08 12:56:28 CST, end at 日 2018-01-14 21:28:53 CST. --
 1月 08 12:56:28 localhost.localdomain systemd-journal[342]: Runtime journal is us
 1月 08 12:56:28 localhost.localdomain systemd-journal[342]: Runtime journal is us
 1月 08 12:56:28 localhost.localdomain kernel: Initializing cgroup subsys cpuset
 1月 08 12:56:28 localhost.localdomain kernel: Initializing cgroup subsys cpu
 1月 08 12:56:28 localhost.localdomain kernel: Initializing cgroup subsys cpuacct
 1月 08 12:56:28 localhost.localdomain kernel: Linux version 3.10.0-327.el7.x86_64
 1月 08 12:56:28 localhost.localdomain kernel: Command line: BOOT_IMAGE=/vmlinuz-3
 1月 08 12:56:28 localhost.localdomain kernel: Disabled fast string operations
 1月 08 12:56:28 localhost.localdomain kernel: e820: BIOS-provided physical RAM ma
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x0000000000000000-
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x000000000009ec00-
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x00000000000dc000-
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x0000000000100000-
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x000000003fee0000-
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x000000003feff000-
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x000000003ff00000-
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x00000000f0000000-
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x00000000fec00000-
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x00000000fee00000-
 1月 08 12:56:28 localhost.localdomain kernel: BIOS-e820: [mem 0x00000000fffe0000-
 1月 08 12:56:28 localhost.localdomain kernel: NX (Execute Disable) protection: ac
 1月 08 12:56:28 localhost.localdomain kernel: SMBIOS 2.7 present.
 1月 08 12:56:28 localhost.localdomain kernel: DMI: VMware, Inc. VMware Virtual Pl
 1月 08 12:56:28 localhost.localdomain kernel: Hypervisor detected: VMware
...skipping...
 1月 14 21:28:23 localhost.localdomain dbus[912]: [system] Activating via systemd:
 1月 14 21:28:23 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Activ
 1月 14 21:28:23 localhost.localdomain systemd[1]: Starting Fingerprint Authentica
 1月 14 21:28:23 localhost.localdomain dbus[912]: [system] Successfully activated 
 1月 14 21:28:23 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Succe
 1月 14 21:28:23 localhost.localdomain systemd[1]: Started Fingerprint Authenticat
 1月 14 21:28:23 localhost.localdomain fprintd[13733]: Launching FprintObject
 1月 14 21:28:23 localhost.localdomain fprintd[13733]: ** Message: D-Bus service l
 1月 14 21:28:23 localhost.localdomain fprintd[13733]: ** Message: entering main l
 1月 14 21:28:30 localhost.localdomain sudo[13732]:     test : TTY=pts/0 ; PWD=/ho
 1月 14 21:28:30 localhost.localdomain su[13737]: (to root) test on pts/0
 1月 14 21:28:30 localhost.localdomain su[13737]: pam_unix(su:session): session op
 1月 14 21:28:30 localhost.localdomain dbus[912]: [system] Activating service name
 1月 14 21:28:31 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Activ
 1月 14 21:28:31 localhost.localdomain dbus[912]: [system] Successfully activated 
 1月 14 21:28:31 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Succe
 1月 14 21:28:53 localhost.localdomain fprintd[13733]: ** Message: No devices in u
 1月 14 21:30:01 localhost.localdomain kernel: SELinux: initialized (dev tmpfs, ty
 1月 14 21:30:01 localhost.localdomain systemd[1]: Created slice user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Started Session 53 of user root
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting Session 53 of user roo
 1月 14 21:30:01 localhost.localdomain CROND[13799]: (root) CMD (/usr/lib64/sa/sa1
 1月 14 21:30:01 localhost.localdomain systemd[1]: Removed slice user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Stopping user-0.slice.
...skipping...
 1月 14 21:28:23 localhost.localdomain dbus[912]: [system] Activating via systemd:
 1月 14 21:28:23 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Activ
 1月 14 21:28:23 localhost.localdomain systemd[1]: Starting Fingerprint Authentica
 1月 14 21:28:23 localhost.localdomain dbus[912]: [system] Successfully activated 
 1月 14 21:28:23 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Succe
 1月 14 21:28:23 localhost.localdomain systemd[1]: Started Fingerprint Authenticat
 1月 14 21:28:23 localhost.localdomain fprintd[13733]: Launching FprintObject
 1月 14 21:28:23 localhost.localdomain fprintd[13733]: ** Message: D-Bus service l
 1月 14 21:28:23 localhost.localdomain fprintd[13733]: ** Message: entering main l
 1月 14 21:28:30 localhost.localdomain sudo[13732]:     test : TTY=pts/0 ; PWD=/ho
 1月 14 21:28:30 localhost.localdomain su[13737]: (to root) test on pts/0
 1月 14 21:28:30 localhost.localdomain su[13737]: pam_unix(su:session): session op
 1月 14 21:28:30 localhost.localdomain dbus[912]: [system] Activating service name
 1月 14 21:28:31 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Activ
 1月 14 21:28:31 localhost.localdomain dbus[912]: [system] Successfully activated 
 1月 14 21:28:31 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Succe
 1月 14 21:28:53 localhost.localdomain fprintd[13733]: ** Message: No devices in u
 1月 14 21:30:01 localhost.localdomain kernel: SELinux: initialized (dev tmpfs, ty
 1月 14 21:30:01 localhost.localdomain systemd[1]: Created slice user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Started Session 53 of user root
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting Session 53 of user roo
 1月 14 21:30:01 localhost.localdomain CROND[13799]: (root) CMD (/usr/lib64/sa/sa1
 1月 14 21:30:01 localhost.localdomain systemd[1]: Removed slice user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Stopping user-0.slice.

  • journalctl -n 列出最後10行資料
[root@localhost test]# journalctl -n
-- Logs begin at 一 2018-01-08 12:56:28 CST, end at 日 2018-01-14 21:30:01 CST. --
 1月 14 21:28:31 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Succe
 1月 14 21:28:53 localhost.localdomain fprintd[13733]: ** Message: No devices in u
 1月 14 21:30:01 localhost.localdomain kernel: SELinux: initialized (dev tmpfs, ty
 1月 14 21:30:01 localhost.localdomain systemd[1]: Created slice user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Started Session 53 of user root
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting Session 53 of user roo
 1月 14 21:30:01 localhost.localdomain CROND[13799]: (root) CMD (/usr/lib64/sa/sa1
 1月 14 21:30:01 localhost.localdomain systemd[1]: Removed slice user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Stopping user-0.slice.
  • journalctl -n 20 列出最後20行資料
[root@localhost test]# journalctl -n 20
-- Logs begin at 一 2018-01-08 12:56:28 CST, end at 日 2018-01-14 21:30:01 CST. --
 1月 14 21:28:23 localhost.localdomain systemd[1]: Started Fingerprint Authenticat
 1月 14 21:28:23 localhost.localdomain fprintd[13733]: Launching FprintObject
 1月 14 21:28:23 localhost.localdomain fprintd[13733]: ** Message: D-Bus service l
 1月 14 21:28:23 localhost.localdomain fprintd[13733]: ** Message: entering main l
 1月 14 21:28:30 localhost.localdomain sudo[13732]:     test : TTY=pts/0 ; PWD=/ho
 1月 14 21:28:30 localhost.localdomain su[13737]: (to root) test on pts/0
 1月 14 21:28:30 localhost.localdomain su[13737]: pam_unix(su:session): session op
 1月 14 21:28:30 localhost.localdomain dbus[912]: [system] Activating service name
 1月 14 21:28:31 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Activ
 1月 14 21:28:31 localhost.localdomain dbus[912]: [system] Successfully activated 
 1月 14 21:28:31 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Succe
 1月 14 21:28:53 localhost.localdomain fprintd[13733]: ** Message: No devices in u
 1月 14 21:30:01 localhost.localdomain kernel: SELinux: initialized (dev tmpfs, ty
 1月 14 21:30:01 localhost.localdomain systemd[1]: Created slice user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Started Session 53 of user root
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting Session 53 of user roo
 1月 14 21:30:01 localhost.localdomain CROND[13799]: (root) CMD (/usr/lib64/sa/sa1
 1月 14 21:30:01 localhost.localdomain systemd[1]: Removed slice user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Stopping user-0.slice.
lines 1-21/21 (END)
  • journalctl -xn 列出最後發生的事件,並提供相關資訊
[root@localhost test]# journalctl -xn
-- Logs begin at 一 2018-01-08 12:56:28 CST, end at 日 2018-01-14 21:30:01 CST. --
 1月 14 21:28:31 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Succe
 1月 14 21:28:53 localhost.localdomain fprintd[13733]: ** Message: No devices in u
 1月 14 21:30:01 localhost.localdomain kernel: SELinux: initialized (dev tmpfs, ty
 1月 14 21:30:01 localhost.localdomain systemd[1]: Created slice user-0.slice.
-- Subject: Unit user-0.slice has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit user-0.slice has finished starting up.
-- 
-- The start-up result is done.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting user-0.slice.
-- Subject: Unit user-0.slice has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit user-0.slice has begun starting up.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Started Session 53 of user root
-- Subject: Unit session-53.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-53.scope has finished starting up.
-- 
lines 1-25

  • journalctl --follow 持續列出最後10行的事件紀錄(類似tail -n 10 -f /var/log/message那樣)
[root@localhost test]# journalctl --follow
-- Logs begin at 一 2018-01-08 12:56:28 CST. --
 1月 14 21:28:31 localhost.localdomain dbus-daemon[912]: dbus[912]: [system] Successfully activated service 'org.freedesktop.problems'
 1月 14 21:28:53 localhost.localdomain fprintd[13733]: ** Message: No devices in use, exit
 1月 14 21:30:01 localhost.localdomain kernel: SELinux: initialized (dev tmpfs, type tmpfs), uses transition SIDs
 1月 14 21:30:01 localhost.localdomain systemd[1]: Created slice user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Started Session 53 of user root.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Starting Session 53 of user root.
 1月 14 21:30:01 localhost.localdomain CROND[13799]: (root) CMD (/usr/lib64/sa/sa1 1 1)
 1月 14 21:30:01 localhost.localdomain systemd[1]: Removed slice user-0.slice.
 1月 14 21:30:01 localhost.localdomain systemd[1]: Stopping user-0.slice.



上一篇
Linux從零開始(6/30): 登錄檔的二三事
下一篇
Linux從零開始(8/30): 固定IP、網卡設定
系列文
Linux從零開始30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
Wolke
iT邦研究生 5 級 ‧ 2017-12-30 21:14:21

還沒補

我要留言

立即登入留言